package stu.sup.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import stu.sup.entity.AddressInfo;
import stu.sup.entity.AddressInfoExample;
import stu.sup.mapper.AddressInfoMapper;
import stu.sup.service.IAddressInfoService;

import java.util.List;

import java.util.List;

/**
 * Created by HUAWEI on 2020/6/23.
 */
@Service
@Transactional
public class AddressInfoServiceImpl implements IAddressInfoService {

    @Autowired
    AddressInfoMapper addressInfoMapper;


    @Override
    public boolean addAdress(int loginId, String username, String adress, String telephone) {
        AddressInfo addressInfo=new AddressInfo();
        addressInfo.setUserLoginId(loginId);
        addressInfo.setName(username);
        addressInfo.setAddress(adress);
        addressInfo.setTelephone(telephone);
        int count=addressInfoMapper.insert(addressInfo);
        return count==0?false:true;
    }

    @Override
    public boolean delete(int id) {
        int count=addressInfoMapper.deleteByPrimaryKey(id);
        return count==0?false:true;
    }

    @Override
    public boolean update(AddressInfo addressInfo) {
        int count=addressInfoMapper.updateByPrimaryKey(addressInfo);
        return count==0?false:true;
    }

    @Override
    public List<AddressInfo> findbyuser(int userid) {
        return null;
    }

    @Override
    public List<AddressInfo> find(int id) {
        AddressInfoExample example=new AddressInfoExample();
        AddressInfoExample.Criteria criteria=example.createCriteria();
        criteria.andUserLoginIdEqualTo(id);
        List<AddressInfo> addressInfos=addressInfoMapper.selectByExample(example);
        return addressInfos;
    }

    @Override
    public List<AddressInfo> selectByLoginId(Integer loginId) {
        List<AddressInfo> addressInfoList = null;

        addressInfoList = addressInfoMapper.selectByLoginId(loginId);

        return addressInfoList;
    }

    @Override
    public AddressInfo selectByPrimaryKey(Integer addressInfoId) {
        AddressInfo addressInfo = new AddressInfo();
        addressInfo = addressInfoMapper.selectByPrimaryKey(addressInfoId);
        return addressInfo;
    }


}
